<template>
  <uni-nav-bar :title="title" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
  <scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="scroll-box"
    :style="{ height: pageHeight + 'px' }">
    <view class="package" v-for="item in frinedList" :key="item.id">
      <view class="space-between">
        <view>{{item.memo}}</view>
        <view>{{item.nums}}</view>
      </view>
      <view class="space-between" style="font-size: 26rpx;margin-top:15rpx;">
        <view>{{item.createtime}}</view>
        <view>变动后：{{item.after}}</view>
      </view>
    </view>
    <Popu v-if="frinedList.length<1" :pageHeight="pageHeight" text="暂无商品列表"></Popu>
  </scroll-view>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import { navBack } from '@/utils/navigator';
  import { showLoading } from '@/utils/prompt';
  import { onLoad } from '@dcloudio/uni-app';
  import Popu from '@c/earthPushing/common/popu.vue';
  import { getKuGoodsChangeList } from '@/gql/warehouse';
  import { toPublish } from '@mqtt';
  /**
   * 商品信息
   * @param wareID 商品的库ID
   * @param shopID 商品ID
   * @param title 页面标题
   * @param pageHeight 页面高度
   * @param frinedList 商品所在仓库变动明细列表
   * @param lastPage 总页数
   * @param currentPage 当前页数
   */
  const wareID = ref() //仓库ID
  const shopID = ref() //商品ID
  const title = ref()
  const pageHeight = ref();
  const frinedList = ref([])
  const lastPage = ref(1);
  const currentPage = ref(1);
  uni.getSystemInfo({
    success: function (res) {
      pageHeight.value = res.windowHeight - 70;
    },
  });
  onLoad((pearm) => {
    wareID.value = Number(pearm.id)
    shopID.value = Number(pearm.shopID)
    title.value = pearm.name
    init()
  })
  /**
   * 获取商品信息
   * @param {Number} page  获取商品列表数据
   * @param {String} id  商品的库ID
   */
  function init() {
    showLoading()
    const payload = {
      query: getKuGoodsChangeList,
      variables: {
        page: currentPage.value,
        id: Number(wareID.value)
      },
    };
    toPublish(
      'ql/control/getKuGoodsChangeList',
      payload,
      (obj : any) => {
        const { getKuGoodsChangeList } = obj.data;
        frinedList.value = [...frinedList.value, ...getKuGoodsChangeList.list];
        lastPage.value = getKuGoodsChangeList.lastpage;
      }
    );
  }
  /**
   * 加载更多
   */
  function loadMore() {
    if (currentPage.value < lastPage.value) {
      currentPage.value++;
      init();
    }
  }
</script>

<style scoped lang="less">
</style>